<?php

$array = array("A","B","C","D","E","F","G","H","I","J");
$limitItemsPerRow = 2;
$limitRows = 2;
$changeRow = 0;
$changePage = 0;
$countItem = 0;
$countRow = 1;
$html = "< ul > <br />";
foreach($array as $key => $val){
    if(!$key){
        $html .= "< li > <br /> < div >";
    }
    if($changeRow){
        $countItem = 0;
        $countRow ++;
        if($changePage){
            $countRow = 1;
            $html .= "<br /> < / div > <br /> < / li > <br /> < li >";
        } else {
            $html .= "<br />< / div >";
        }
        $html .= "<br /> <  div >";
    }
    $html .= "<br /> < div >" . $val . "< / div >";
    $countItem ++;
    $changeRow = $countItem == $limitItemsPerRow ? 1 : 0;
    $changePage = $countRow == $limitRows ? 1 : 0;
}
$html .= " <br />< / div > <br /> < / li > <br /> < / ul >";
echo $html;
?>
